#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=60;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn][maxn][maxn];
void pre(){
     memset(dp,0x3f,sizeof(dp));
     for(LL i=0;i<=30;i++){
         for(LL j=0;j<=30;j++){
             dp[i][j][0]=0;
             if(i*j<=50) dp[i][j][i*j]=0;
            ///dp[i][j][min(i*j,(LL)50)]=0;
         }
     }
     for(LL i=1;i<=30;i++){
        for(LL j=1;j<=30;j++){
            for(LL k=1;k<=min(i*j,(LL)50);k++){
                for(LL x=1;x<=i;x++){
                    LL temp=min(k,x*j);
                    for(LL o=0;o<=temp;o++){
                        dp[i][j][k]=min(dp[i][j][k],dp[x][j][o]+dp[i-x][j][k-o]+j*j);
                    }
                }
                for(LL y=1;y<=j;y++){
                    LL temp=min(k,y*i);
                    for(LL o=0;o<=temp;o++){
                        dp[i][j][k]=min(dp[i][j][k],dp[i][y][o]+dp[i][j-y][k-o]+i*i);
                    }
                }
            }
        }
     }
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    pre();
    LL t;cin>>t;
    while(t--){
        LL n,m,k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<"\n";
    }
   	return 0;
}
